import { pathToBase64, base64ToPath } from '../js_sdk/mmmm-image-tools/index.js'
module.exports = (a,vue) => {
	a.pathtobase64 = pathToBase64;
	a.base64topath = base64ToPath;
	a.savedata = (key, value, time) => {
		if (!time) time = '';
		var now = new Date().getTime(),
			adtime = '';
		if (time.indexOf('s') != -1) {
			adtime = Number(parseInt(time)) * 1000;
		} else if (time.indexOf('m') != -1) {
			adtime = Number(parseInt(time)) * 60 * 1000;
		} else if (time.indexOf('h') != -1) {
			adtime = Number(parseInt(time)) * 60 * 60 * 1000;
		} else if (time.indexOf('d') != -1) {
			adtime = Number(parseInt(time)) * 60 * 60 * 24 * 1000;
		} else {}
		var T = adtime ? (now + adtime) : '';
		var lst = uni.getStorageInfoSync();
		for (var i in lst.keys) {
			var o = lst.keys[i];
			if (o.indexOf(key + '|') != -1) {
				uni.removeStorageSync(o);
				break;
			}
		}
		uni.setStorageSync(key + '|' + T, value);
	}
	a.getdata = (key) => {
		var lst = uni.getStorageInfoSync(),
			value = null;
		for (var i in lst.keys) {
			var o = lst.keys[i];
			if (o.indexOf(key + '|') != -1) {
				var oldt = o.split('|');
				if (oldt.length > 1 && oldt[1]) {
					var nowt = new Date().getTime();
					var sot = Number(oldt[1]) - nowt;
					if (sot > 0) {
						// console.log(sot)
						value = uni.getStorageSync(o);
					} else {
						uni.removeStorageSync(o);
					}
				} else {
					value = uni.getStorageSync(o);
				}
				break;
			}
		}
		return value;
	}
	a.removedata = (key) => {
		if (key) {
			var lst = uni.getStorageInfoSync();
			for (var i in lst.keys) {
				var o = lst.keys[i];
				if (o.indexOf(key + '|') != -1) {
					uni.removeStorageSync(o);
					break;
				}
			}
		} else {
			uni.clearStorageSync();
		}

	}
	
	
	
}
